﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Guwave.MonitorDevice.WPFClientApp.ViewModel
{
    /// <summary>
    /// 继承ICommand接口
    /// </summary>
    public class CommandBase : ICommand
    {
        public event EventHandler CanExecuteChanged;

        public Func<object, bool> DoCanExecute { get; set; }

        /// <summary>
        /// 执行的具体动作
        /// </summary>
        public Action<object> DoExecute { get; set; }

        /// <summary>
        /// 能不能执行
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public bool CanExecute(object parameter)
        {
            return DoCanExecute?.Invoke(parameter) == true;
        }

        /// <summary>
        /// 执行
        /// </summary>
        /// <param name="parameter"></param>
        public void Execute(object parameter)
        {
            DoExecute?.Invoke(parameter);
        }
    }
}
